/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ListRendererBonos.java
 *
 * Created on 16/04/2011, 05:19:52 PM
 */

package frontera.interfaz.listRenderer;

import entidad.Bono;
import java.awt.Color;
import java.awt.Component;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 *
 * @author Sebastian
 */
public class ListRendererBonos extends javax.swing.JPanel implements ListCellRenderer {

    /** Creates new form ListRendererBonos */
    public ListRendererBonos() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelFecha = new javax.swing.JLabel();
        labelDescripcion = new javax.swing.JLabel();
        labelCantidad = new javax.swing.JLabel();

        setLayout(new java.awt.GridLayout());

        labelFecha.setText("Fecha");
        add(labelFecha);

        labelDescripcion.setText("Descripcion");
        add(labelDescripcion);

        labelCantidad.setText("Cantidad");
        add(labelCantidad);
    }// </editor-fold>//GEN-END:initComponents

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

        Bono bono = (Bono)value;

        NumberFormat formatter = new DecimalFormat("#0.00");

        labelFecha.setText(Integer.toString(bono.getFecha().get(Calendar.DATE)));
        labelDescripcion.setText(bono.getDescripcion());
        labelCantidad.setText(formatter.format(bono.getCantidadBono()));

        if(isSelected){
            this.setBackground(new Color(200, 200, 255));
        }
        else{
            this.setBackground(new Color(255, 255, 255));
        }

        return this;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel labelCantidad;
    private javax.swing.JLabel labelDescripcion;
    private javax.swing.JLabel labelFecha;
    // End of variables declaration//GEN-END:variables

}
